<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;

$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return=array();
$uniacid=$_SESSION['uniacid'];
$mid=$_SESSION['uid'];
$merchid=$this->checklogin();
if($_RQ['op']=='main'){
	$orderid=intval($_RQ['id']);
	$verifycode=$_RQ['ordersn'];
	if (empty($verifycode)) {
			exi('请输入核销码!','error','jy_tour/merch.verify/');
	}
	$order_verify=$this->pdo_get('order',array('ordersn'=>$verifycode));
	if (empty($order_verify)) 
	{
		exi('核销码错误,无权核销','error','jy_tour/merch.verify/');   
	}
	if($orderid){
		$order=pdo_get('jy_tour_order',array('uniacid'=>$uniacid,'id'=>$orderid));
	}else{
		$order=pdo_get('jy_tour_order',array('uniacid'=>$uniacid,'id'=>$order_verify['id']));
	}
	$saler=pdo_get('jy_tour_merch',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
	if ($saler['id']!=$order['merchid']) 
	{
		exi('您不是该商户的核销员,无权核销','error','jy_tour/merch.verify/');   
	}
	if (empty($order)) {
			exi('订单不存在!','error','jy_tour/merch.verify/');
	}
	if ($order['status'] ==3) {	
		exi('该核销码已被使用!','error','jy_tour/merch.verify/');		
	}
	$order_goods=$this->pdo_getall('spot',array('id'=>$order['spot_id']));
	$return['post']=array(
		'orderid'=>$order['id'],
		'verify_code'=>$verifycode,
	);
	$return['order']=$order;
	$return['order_goods']=$order_goods;
	set_html('title','核销');
    exi($return);
}

if($_RQ['op']=='post'){
	$post=get_postdata();
	$orderid=intval($post['orderid']);
	$verify_code=trim($post['verify_code']);
	$this->model('merch')->order_verify($verify_code,$_SESSION['uid']);
	exi('核销成功！','','jy_tour/merch.verify/');
	
}